
*** Set Fixed Effects and Clustering
global fe "courtq"
global clusvar "partyr"

*** Set general controls
global exactcontrols "black hisp female blackfemale hispfemale  ageatfiling age2 age3 sh_hhpov med_grossrent rentowed multicase"

**************************************
***** Table - Randomization/ Balance *   
**************************************
label var stringency "Evict Order"

global randvars "ageatfiling female black whitenothisp hisp sh_hhpov rentowed nopriorcase"

reghdfe evictionorder $randvars   if samp==1, absorb($fe)  absorb($clusvar)
local F_evict_cc_nyc `=e(F)'
local pval_evict_cc_nyc `=Ftail(e(rank),e(df_r),e(F))'
local N_evict_cc_nyc `e(N)'

reghdfe stringency $randvars  if samp==1, absorb($fe)  absorb($clusvar)
local F_judge_cc_nyc `=e(F)'
local pval_judge_cc_nyc `=Ftail(e(rank),e(df_r),e(F))'
local N_judge_cc_nyc `e(N)'

frame change random

gen F_evict=`F_evict'
gen F_judge=`F_judge'
gen F_evict_cc_nyc=`F_evict_cc_nyc'
gen F_judge_cc_nyc=`F_judge_cc_nyc'

gen double pval_evict=`pval_evict'
gen double pval_judge=`pval_judge'
gen double pval_evict_cc_nyc=`pval_evict_cc_nyc'
gen double pval_judge_cc_nyc=`pval_judge_cc_nyc'

gen N_evict=`N_evict'
gen N_judge=`N_judge'
gen N_evict_cc_nyc=`N_evict_cc_nyc'
gen N_judge_cc_nyc =`N_judge_cc_nyc'

replace variablename="Rent Amount Owed" if variablename=="rentowed"
replace variablename="Age at Filing" if variablename=="ageatfiling"
replace variablename="Black" if variablename=="black"
replace variablename="Female" if variablename=="female"
replace variablename="White, Not-Hispanic"  if variablename=="whitenothisp"
replace variablename="Hispanic"  if variablename=="hisp"
replace variablename="First Case" if variablename=="nopriorcase"
replace variablename="Tract Poverty Rate"  if variablename=="sh_hhpov"
replace variablename="Tract Median Rent"  if variablename=="med_grossrent"

drop t pvalue ll ul df crit eform

save ${Inputs}/NY_main_balance.dta, replace

frame change default



****************************************
***** Table - Summary Statistics *******   
****************************************
*** create rent owed in 1000's
gen amountowed=rentowed/1000

*** label variables
label var ageatfiling "Age at Filing"
label var female "Female"
label var black "Black"
label var hisp "Hispanic"
label var ly1t2earn  "Earnings Q -1,-8"
label var ly1t2employ   "Employment Q -1,-8"
label var sh_hhpov "Tract Poverty Rate"
label var rent "Tract Median Rent"
label var amountowed "Rent Amount Owed"
label var nopriorcase "No Previous Case"
label var noattorney "No Attorney"

global sumstatsvars "ageatfiling female black hisp amountowed nopriorcase noattorney sh_hhpov rent ly1t2earn ly1t2employ"

**** Calculate Summary Stats
capture frame drop summary
frame create summary str55 name mean sd N str50 evicted

foreach v of varlist $sumstatsvars {
	qui {
		sum `v' if samp==1 & evictionorder==1 
		frame post summary ("`: var label `v''") (r(mean)) (r(sd)) (r(N)) ("Evicted")
		sum `v' if samp==1 & evictionorder==0 
		frame post summary ("`: var label `v''") (r(mean)) (r(sd)) (r(N)) ("Not Evicted")
		sum `v' if samp==1  
		frame post summary ("`: var label `v''") (r(mean)) (r(sd)) (r(N)) ("All")
	}
}
frame summary: save ${Inputs}/NY_main_sumstats.dta, replace




***********************************
***** Table - First Stage   *******   
***********************************

frame create fsexclusion beta se str50 specification str35 coef_var N

ivreghdfe evictionorder stringency if samp==1 , absorb($fe) absorb($clusvar)
frame post fsexclusion (_b[stringency]) (_se[stringency]) ("First Stage, No Controls") ("Coefficent on Instrument") (e(N))

ivreghdfe evictionorder stringency $exactcontrols if samp==1 , absorb($fe) absorb($clusvar)
frame post fsexclusion (_b[stringency]) (_se[stringency]) ("First Stage, with Controls") ("Coefficent on Instrument") (e(N))

ivreghdfe evictionorder stringency zeca zstayedexec if samp==1 , absorb($fe) absorb($clusvar)

frame post fsexclusion (_b[stringency]) (_se[stringency]) ("First Stage, with Other Stringency") ("Coefficent on Instrument") (e(N))
frame post fsexclusion (_b[zeca ]) (_se[zeca ]) ("First Stage, with Other Stringency") ("Coefficent on Emergency Assistance Stringency") (e(N))
frame post fsexclusion (_b[zstayedexec]) (_se[zstayedexec]) ("First Stage, with Other Stringency") ("Coefficent on Stays Stringency") (e(N))
frame fsexclusion: saveold ${Inputs}/NY_main_fs.dta, replace

